{% extends "wiki/wiki_base.html" %}

{% block extra-head %}
<script type="text/javascript">
// Creates a new plugin class and a custom listbox
tinymce.create('tinymce.plugins.WikiPlugin', {
    createControl: function(n, cm) {
        switch (n) {
            case 'linkidostron':
                var lista = cm.createListBox('listastron', {
                     title : 'Link do strony',
                     onselect : function(v) {
                        tinyMCE.activeEditor.focus();
                        if (v == 'nowa') {
                            var tytul = prompt('Podaj tytuł strony: ', 'Nowa strona');
                            var tytul_url = tytul.replace(' ','_');
                            tinyMCE.activeEditor.selection.setContent('<a href="' + tytul_url + '">' + tytul + '</a>');
                        }
                        else {
                            tinyMCE.activeEditor.selection.setContent(v);
                        }
                     }
                });

                lista.add('Nowa', 'nowa');
                {% for s in strony %}
                    lista.add('{{ s.tytul}}', '<a href="/wiki/{{ s.tytul_url }}">{{ s.tytul }}</a>' )
                {% endfor %}

                return lista;
        }

        return null;
    }
});

// Register plugin with a short name
tinymce.PluginManager.add('wikiplugin', tinymce.plugins.WikiPlugin);

// Initialize TinyMCE with the new plugin and listbox
/*tinyMCE.init({
    plugins : '-example', // - tells TinyMCE to skip the loading of the plugin
    mode : "textareas",
    theme : "advanced",
    theme_advanced_buttons1 : "mylistbox,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom"
    });
*/
/*
tinyMCE.init({
        "relative_urls": false, 
        "spellchecker_languages": "+polski=pl", 
        "elements": "id_tresc", 
        "language": "pl", 
        "directionality": "ltr", 
        "theme": "simple", 
        "strict_loading_mode": 1, 
        "mode": "exact"
})
*/
</script>

{% endblock %}
{% block content %}
<h1>{{ tytul }}</h1>
<form method="POST" action=".">
    {{ form.as_p }}
<p><input type="submit" name="zapisz" value="Zapisz" /> <input type="submit" name="podglad" value="Podgląd" /></p>
</form>

{% if podglad %}
<h2>Podgląd: </h2>
    {% autoescape off %}
        {{ podglad }}
    {% endautoescape %}
{% endif %}

{% endblock %}
